package cn.assumejson.springframework.context.context.annotation;

import cn.assumejson.springframework.beans.factory.config.BeanDefinition;
import cn.assumejson.springframework.beans.factory.support.RootBeanDefinition;
import cn.assumejson.springframework.context.stereotype.Component;
import cn.hutool.core.util.ClassUtil;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * 解析获取所有的Component 注解
 *
 * @author Mr. Li
 * @version 1.0
 * @since 1.0 2021/12/2 22:31
 */
public class ClassPathScanningCandidateComponentProvider {

    public Set<BeanDefinition> findCandidateComponents(String basePackage) {
        Set<BeanDefinition> candidates = new LinkedHashSet<>();
        Set<Class<?>> classes = ClassUtil.scanPackageByAnnotation(basePackage, Component.class);
        for (Class<?> clazz : classes) {
            candidates.add(new RootBeanDefinition(clazz));
        }
        return candidates;
    }

}
